package cn.quicklydoit.utils;

import cn.quicklydoit.entity.User;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;

/**
 * 生成token
 */
public class TokenUtils {


    /**
     * 根据用户生成token
     * @param user user
     * @return token
     */
    public static String  GenerateToken(User user){
        String token="";
        Algorithm algorithm = Algorithm.HMAC256("secret");
        token = JWT.create()
                .withIssuer("http://quicklydoit.cn/issuer")
                .withClaim("ip",user.getCurrentIp())
                .withClaim("times",user.getCurrentTimes())
                .withClaim("name",user.getName())
                .withClaim("pass",user.getPassword())
                .sign(algorithm);
        return  token;
    }


    public static void main(String[] args) {
        User user=new User();
        user.setId(1L);
        user.setCurrentIp("10.81.126.31");
        user.setCurrentTimes(1l);
        user.setName("123");
        user.setPassword("1213121");
        System.out.println(GenerateToken(user));
        System.out.println(11);
    }

}
